<!--
 * @Descripttion: 
 * @version: @ 1.0.0
 * @Author: 朱江洲
 * @Date: 2022-02-24 14:07:16
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-05-07 10:02:06
-->
<template>
  <div>
    <el-dialog
      title="商机"
      :visible.sync="dialog.OpportunityShow"
      width="60%"
      @close="customerClose"
    >
      <el-table
        :data="tableData"
        @selection-change="handleSelectionChange"
        height="490"
      >
        <template slot="empty" class="emptyBg">
          <img src="@/assets/images/empty.jpg" alt="" />
        </template>
        <el-table-column type="selection"></el-table-column>
        <template v-for="(item, index) in switchShow">
          <el-table-column
            :key="index"
            :label="item.label"
            :width="item.width"
            :prop="item.stage"
            v-show="item.value"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
        </template>
      </el-table>
      <el-pagination
        prev-text="上一页"
        next-text="下一页"
        background
        :page-size="pageSize"
        :page-sizes="[10, 20, 30, 40, 50, 100]"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        layout=" ->,total, sizes, prev, pager, next, jumper "
        :total="total"
      >
      </el-pagination>
      <span slot="footer">
        <el-button @click="dialog.OpportunityShow = false">取消</el-button>
        <el-button type="primary" @click="submit" :disabled="disabled">
          确定
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listByCustomer } from "@/api/CRM/comtact";
export default {
  props: {
    dialog: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      pageSize: 10,
      pageNum: 1,
      total: 0,
      disabled: false,
      tableData: [],
      multipleSelection: [],
      switchShow: [
        {
          value: true,
          label: "商机名称",
          stage: "name",
        },
        {
          value: true,
          label: "客户名称",
          stage: "customer",
        },
        { value: true, label: "商机金额", stage: "amount" },
        {
          value: true,
          label: "预计成交日期",
          stage: "dealTime",
          width: "180",
        },
        {
          value: true,
          label: "商机状态组",
          stage: "opportunityStatusName",
          width: "100",
        },
        {
          value: true,
          label: "备注",
          stage: "remark",
        },
        {
          value: true,
          label: "更新时间",
          stage: "updataTime",
        },
        {
          value: true,
          label: "负责人",
          stage: "directorName",
          width: "120",
        },
        {
          value: true,
          label: "创建人",
          stage: "createBy",
          width: "120",
        },
        {
          value: true,
          label: "创建时间",
          stage: "createTime",
          width: "180",
        },
      ],
    };
  },
  created() {
    this.getCustomerList();
  },
  methods: {
    // 关闭
    customerClose() {
      this.multipleSelection = [];
      this.dialog.OpportunityEject = false;
    },
        handleSizeChange(val) {
      this.pageSize = val;
      this.pageNum = 1;
       this.getCustomerList();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getCustomerList();
    },
    // 提交
    submit() {
      this.$parent.contactForm.opportunityId = this.multipleSelection[0].id;
      this.$parent.contactForm.opportunity = this.multipleSelection[0].name;
      this.dialog.OpportunityShow = false;
    },
    // 多选框
    handleSelectionChange(val) {
      this.multipleSelection = val;
      if (val.length > 1) {
        this.disabled = true;
      }
      if (val.length > 1) {
        this.disabled = true;
      } else {
        this.disabled = false;
      }
    },
    getCustomerList() {
      listByCustomer({
        pageSize: this.pageSize,
        pageNum: this.pageNum,
        customerId: this.$parent.contactForm.customerId,
      }).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
      });
    },
  },
};
</script>

<style lang="less" scoped>
.el-pagination {
  margin-top: 24px;
  /deep/ .el-pagination__total {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    margin-right: 25px;
  }
  /deep/ .btn-prev {
    width: 80px;
    height: 40px;
    text-align: center;
  }
  /deep/ .btn-next {
    width: 80px;
    height: 40px;
    text-align: center;
  }
  /deep/ .number {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .el-input__inner {
    // width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .more {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .el-pagination__jump {
    .el-input__inner {
      width: 40px;
      height: 40px;
    }
  }
}
</style>